package ee.ttu.karileet.serviceshop.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ee.ttu.karileet.serviceshop.dao.EmployeeDAO;
import ee.ttu.karileet.serviceshop.model.Employee;

@Service("employeeDAO")
public class EmployeeDAOImpl implements EmployeeDAO {
	
	@Autowired
	private SessionFactory sessionFactory;
	
	@Override
	public void insertEmployee(Employee object) {
		sessionFactory.getCurrentSession().save(object);
	}

	@Override
	public Employee getEmployeeById(long id) {
		return (Employee) sessionFactory.
			      getCurrentSession().
			      get(Employee.class, id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Employee> getEmployees() {
	    Criteria criteria = sessionFactory.
	    	      getCurrentSession().
	    	      createCriteria(Employee.class);
	    return criteria.list();
	}

}
